import React, { PureComponent } from 'react'
import Header from '../../components/Header/Header'
import Banner from './components/Banner/Banner'
import New from './components/New/New'
import Groupon from './components/Groupon/Groupon'
import Seckill from './components/Seckill/Seckill'
import IndexGoods from './components/IndexGoods/IndexGoods'
import { bindActionCreators } from 'redux'
import { connect } from 'react-redux'
import { actions, getBanner, getGroupOn, getIndexGoods, getN, getNew, getSeckill } from '../../store/modules/home'

export class Home extends PureComponent {
  componentDidMount() {
    let {home:{reqBanner,reqNew,reqGroupOn,reqSeckill,reqIndexGoods}} = this.props
    reqBanner()
    reqNew()
    reqGroupOn()
    reqSeckill()
    reqIndexGoods()
  }

  render() {
    let {banner,newList,groupon,seckill,indexGoods,n,home:{newGoods}} = this.props

    return (
      <div>
        <Header title="首页"></Header>
        <Banner banner={banner}></Banner>
        <New newList={newList}></New>
        <Groupon groupon={groupon}></Groupon>
        <Seckill seckill={seckill}></Seckill>
        <IndexGoods indexGoods={indexGoods} n={n} changen={n=>newGoods(n)}></IndexGoods>
      </div>
    )
  }
}

const mapStateToProps = state =>{
  return {
    banner:getBanner(state),
    newList:getNew(state),
    groupon:getGroupOn(state),
    seckill:getSeckill(state),
    indexGoods:getIndexGoods(state),
    n:getN(state)
  }
}

const mapDispatchToProps = dispatch => {
  return {
    home:bindActionCreators(actions,dispatch)
  }
}

export default connect(mapStateToProps,mapDispatchToProps)(Home)